package com.dingqb.ktdemo.oop.inherited

class TestT {
	fun getExtendM() {
		var user = User();
		user.getName();
		user.getExtendMethod();

		user.getTT();

		var userA = UserA();
		userA.getName();
		userA.getExtendMethod();
	}

	// 扩展函数 何处定义 类名.方法名(){}
	fun User.getTT() {
		println("User.getTT");
	}
}

fun main() {
	println("TestT");
	var tt = TestT();
	tt.getExtendM();
	//
	var user = User();
	var data: Data
	data = user.swap(11, 22);
	println(data.toString());

	var nn = null;
	println(nn.toString());
	

}


fun User.swap(index1: Int, index2: Int): Data {
	var d = Data();
	d.a = index2
	d.b = index1
	return d;

}


class Data : Any() {
	open var a = 0
	open var b = 0;
	override fun toString(): String {
		println("override fun toStirng():Stirng ");
		return "a==" + a + ",b==" + b
	}
}

/**
 */
fun Any?.toString(): String {
	println("\nAny.toStirng()")
	if (this == null) return "null"
	// 空检测之后，“this”会自动转换为非空类型，所以下面的 toString()
	// 解析为 Any 类的成员函数
	return toString()
}
